package com.example.creditscore;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

public class Credit_score_form_sec_b extends Activity {
	/**
	 * @uml.property  name="tvCard2"
	 * @uml.associationEnd  
	 */
	private TextView tvCard2;
	/**
	 * @uml.property  name="tvCardNo2"
	 * @uml.associationEnd  
	 */
	private TextView tvCardNo2;
	/**
	 * @uml.property  name="etCardNo2"
	 * @uml.associationEnd  
	 */
	private EditText etCardNo2;
	/**
	 * @uml.property  name="tvDateOpen2"
	 * @uml.associationEnd  
	 */
	private TextView tvDateOpen2;
	/**
	 * @uml.property  name="etDateOpen2"
	 * @uml.associationEnd  
	 */
	private TextView etDateOpen2;
	/**
	 * @uml.property  name="etDateOpen"
	 * @uml.associationEnd  
	 */
	private TextView etDateOpen;
	/**
	 * @uml.property  name="tvAvgSpending2"
	 * @uml.associationEnd  
	 */
	private TextView tvAvgSpending2;
	/**
	 * @uml.property  name="etAvgSpending2"
	 * @uml.associationEnd  
	 */
	private EditText etAvgSpending2;
	/**
	 * @uml.property  name="tvPaymentPattern2"
	 * @uml.associationEnd  
	 */
	private TextView tvPaymentPattern2;
	/**
	 * @uml.property  name="etPaymentPattern2"
	 * @uml.associationEnd  
	 */
	private EditText etPaymentPattern2;
	/**
	 * @uml.property  name="tvCreditCardConduct2"
	 * @uml.associationEnd  
	 */
	private TextView tvCreditCardConduct2;
	/**
	 * @uml.property  name="radioSatisfactory2"
	 * @uml.associationEnd  
	 */
	private RadioButton radioSatisfactory2;
	/**
	 * @uml.property  name="radioUnsatisfactory2"
	 * @uml.associationEnd  
	 */
	private RadioButton radioUnsatisfactory2;
	/**
	 * @uml.property  name="tvCard3"
	 * @uml.associationEnd  
	 */
	private TextView tvCard3;
	/**
	 * @uml.property  name="tvCardNo3"
	 * @uml.associationEnd  
	 */
	private TextView tvCardNo3;
	/**
	 * @uml.property  name="etCardNo3"
	 * @uml.associationEnd  
	 */
	private EditText etCardNo3;
	/**
	 * @uml.property  name="tvDateOpen3"
	 * @uml.associationEnd  
	 */
	private TextView tvDateOpen3;
	/**
	 * @uml.property  name="etDateOpen3"
	 * @uml.associationEnd  
	 */
	private TextView etDateOpen3;
	/**
	 * @uml.property  name="tvAvgSpending3"
	 * @uml.associationEnd  
	 */
	private TextView tvAvgSpending3;
	/**
	 * @uml.property  name="etAvgSpending3"
	 * @uml.associationEnd  
	 */
	private EditText etAvgSpending3;
	/**
	 * @uml.property  name="tvPaymentPattern3"
	 * @uml.associationEnd  
	 */
	private TextView tvPaymentPattern3;
	/**
	 * @uml.property  name="etPaymentPattern3"
	 * @uml.associationEnd  
	 */
	private EditText etPaymentPattern3;
	/**
	 * @uml.property  name="tvCreditCardConduct3"
	 * @uml.associationEnd  
	 */
	private TextView tvCreditCardConduct3;
	/**
	 * @uml.property  name="radioSatisfactory3"
	 * @uml.associationEnd  
	 */
	private RadioButton radioSatisfactory3;
	/**
	 * @uml.property  name="radioUnsatisfactory3"
	 * @uml.associationEnd  
	 */
	private RadioButton radioUnsatisfactory3;
	/**
	 * @uml.property  name="addCardBtn"
	 * @uml.associationEnd  
	 */
	private Button addCardBtn;
	/**
	 * @uml.property  name="removeCardBtn"
	 * @uml.associationEnd  
	 */
	private Button removeCardBtn;
	/**
	 * @uml.property  name="nextPageBtn"
	 * @uml.associationEnd  
	 */
	private Button nextPageBtn;
	/**
	 * @uml.property  name="backPageBtn"
	 * @uml.associationEnd  
	 */
	private Button backPageBtn;
	/**
	 * @uml.property  name="dateOpenBtn"
	 * @uml.associationEnd  
	 */
	private Button dateOpenBtn;
	/**
	 * @uml.property  name="dateOpenBtn2"
	 * @uml.associationEnd  
	 */
	private Button dateOpenBtn2;
	/**
	 * @uml.property  name="dateOpenBtn3"
	 * @uml.associationEnd  
	 */
	private Button dateOpenBtn3;
	/**
	 * @uml.property  name="cardNum"
	 */
	private int cardNum = 1;
	/**
	 * @uml.property  name="mYear"
	 */
	private int mYear;
	/**
	 * @uml.property  name="mMonth"
	 */
	private int mMonth;
	/**
	 * @uml.property  name="mDay"
	 */
	private int mDay;
	static final int DATE_DIALOG_ID = 0;
	static final int DATE_DIALOG_ID2 = 1;
	static final int DATE_DIALOG_ID3 = 2;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.credit_score_form_sec_b);
		
		etDateOpen=(TextView) findViewById(R.id.etDateOpen);
		tvCard2 = (TextView) findViewById (R.id.tvCard2);
		tvCardNo2 = (TextView) findViewById (R.id.tvCardNo2);
		etCardNo2 = (EditText) findViewById (R.id.etCardNo2);
		tvDateOpen2 = (TextView) findViewById (R.id.tvDateOpen2);
		etDateOpen2 = (TextView) findViewById (R.id.etDateOpen2);
		tvAvgSpending2 = (TextView) findViewById (R.id.tvAvgSpending2);
		etAvgSpending2 = (EditText) findViewById (R.id.etAvgSpending2);
		tvPaymentPattern2 = (TextView) findViewById (R.id.tvPaymentPattern2);
		etPaymentPattern2 = (EditText) findViewById (R.id.etPaymentPattern2);
		tvCreditCardConduct2 = (TextView) findViewById (R.id.tvCreditCardConduct2);
		radioSatisfactory2 = (RadioButton) findViewById (R.id.radioSatisfactory2);
		radioUnsatisfactory2 = (RadioButton) findViewById (R.id.radioUnsatisfactory2);
		tvCard3 = (TextView) findViewById (R.id.tvCard3);
		tvCardNo3 = (TextView) findViewById (R.id.tvCardNo3);
		etCardNo3 = (EditText) findViewById (R.id.etCardNo3);
		tvDateOpen3 = (TextView) findViewById (R.id.tvDateOpen3);
		etDateOpen3 = (TextView) findViewById (R.id.etDateOpen3);
		tvAvgSpending3 = (TextView) findViewById (R.id.tvAvgSpending3);
		etAvgSpending3 = (EditText) findViewById (R.id.etAvgSpending3);
		tvPaymentPattern3 = (TextView) findViewById (R.id.tvPaymentPattern3);
		etPaymentPattern3 = (EditText) findViewById (R.id.etPaymentPattern3);
		tvCreditCardConduct3 = (TextView) findViewById (R.id.tvCreditCardConduct3);
		radioSatisfactory3 = (RadioButton) findViewById (R.id.radioSatisfactory3);
		radioUnsatisfactory3 = (RadioButton) findViewById (R.id.radioUnsatisfactory3);
		addCardBtn = (Button) findViewById (R.id.addCardBtn);
		removeCardBtn = (Button) findViewById (R.id.removeCardBtn);
		nextPageBtn = (Button) findViewById (R.id.nextPageBtn);
		backPageBtn = (Button) findViewById (R.id.backPageBtn);
		dateOpenBtn = (Button) findViewById (R.id.dateOpenBtn);
		dateOpenBtn2 = (Button) findViewById (R.id.dateOpenBtn2);
		dateOpenBtn3 = (Button) findViewById (R.id.dateOpenBtn3);
		addCardBtn.setOnClickListener(addCard());
		removeCardBtn.setOnClickListener(rmvCard());
		nextPageBtn.setOnClickListener(nextPage());
		backPageBtn.setOnClickListener(backPage());
		dateOpenBtn.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				showDialog(DATE_DIALOG_ID);
			}
		});
		
		dateOpenBtn2.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				showDialog(DATE_DIALOG_ID2);
			}
		});
		
		dateOpenBtn3.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				showDialog(DATE_DIALOG_ID3);
			}
		});
	}
	

///For Date Application Given
@Override 
protected Dialog onCreateDialog(int id){
	switch(id) {
	case DATE_DIALOG_ID:
		return new DatePickerDialog(this,mDateSetListener, mYear, mMonth,mDay);
	
	case DATE_DIALOG_ID2:
		
		return new DatePickerDialog(this,mDateSetListener2, mYear, mMonth,mDay);
	case DATE_DIALOG_ID3:
		
		return new DatePickerDialog(this,mDateSetListener3, mYear, mMonth,mDay);
	}
	return null;
}
		
	
	private OnClickListener addCard() {
		return new OnClickListener() {
			public void onClick(View v) {
				
				if(cardNum == 1){
					System.out.println("add Card");
					tvCard2.setVisibility(View.VISIBLE);
					tvCardNo2.setVisibility(View.VISIBLE);
					etCardNo2.setVisibility(View.VISIBLE);
					tvDateOpen2.setVisibility(View.VISIBLE);
					etDateOpen2.setVisibility(View.VISIBLE);
					tvAvgSpending2.setVisibility(View.VISIBLE);
					etAvgSpending2.setVisibility(View.VISIBLE);
					tvCreditCardConduct2.setVisibility(View.VISIBLE);
					radioSatisfactory2.setVisibility(View.VISIBLE);
					radioUnsatisfactory2.setVisibility(View.VISIBLE);
					removeCardBtn.setVisibility(View.VISIBLE);
					dateOpenBtn2.setVisibility(View.VISIBLE);
					
				}
				if(cardNum == 2){
					System.out.println("add Card");
					tvCard3.setVisibility(View.VISIBLE);
					tvCardNo3.setVisibility(View.VISIBLE);
					etCardNo3.setVisibility(View.VISIBLE);
					tvDateOpen3.setVisibility(View.VISIBLE);
					etDateOpen3.setVisibility(View.VISIBLE);
					tvAvgSpending3.setVisibility(View.VISIBLE);
					etAvgSpending3.setVisibility(View.VISIBLE);
					tvCreditCardConduct3.setVisibility(View.VISIBLE);
					radioSatisfactory3.setVisibility(View.VISIBLE);
					radioUnsatisfactory3.setVisibility(View.VISIBLE);
					removeCardBtn.setVisibility(View.VISIBLE);
					addCardBtn.setVisibility(View.INVISIBLE);
					dateOpenBtn3.setVisibility(View.VISIBLE);
				}
				cardNum++;
			
			}
		};
	}
	
	private OnClickListener rmvCard() {
		return new OnClickListener() {
			public void onClick(View v) {
			
				if(cardNum == 3){
					System.out.println("rmv Card");
					tvCard3.setVisibility(View.GONE);
					tvCardNo3.setVisibility(View.GONE);
					etCardNo3.setVisibility(View.GONE);
					tvDateOpen3.setVisibility(View.GONE);
					etDateOpen3.setVisibility(View.GONE);
					tvAvgSpending3.setVisibility(View.GONE);
					etAvgSpending3.setVisibility(View.GONE);
					tvCreditCardConduct3.setVisibility(View.GONE);
					radioSatisfactory3.setVisibility(View.GONE);
					radioUnsatisfactory3.setVisibility(View.GONE);
					dateOpenBtn.setVisibility(View.GONE);
					removeCardBtn.setVisibility(View.VISIBLE);
					addCardBtn.setVisibility(View.VISIBLE);
				}
				
				if(cardNum == 2){
					System.out.println("rmv Card");
					tvCard2.setVisibility(View.GONE);
					tvCardNo2.setVisibility(View.GONE);
					etCardNo2.setVisibility(View.GONE);
					tvDateOpen2.setVisibility(View.GONE);
					etDateOpen2.setVisibility(View.GONE);
					tvAvgSpending2.setVisibility(View.GONE);
					etAvgSpending2.setVisibility(View.GONE);
					tvCreditCardConduct2.setVisibility(View.GONE);
					radioSatisfactory2.setVisibility(View.GONE);
					radioUnsatisfactory2.setVisibility(View.GONE);
					dateOpenBtn2.setVisibility(View.GONE);
					removeCardBtn.setVisibility(View.INVISIBLE);
					addCardBtn.setVisibility(View.VISIBLE);
				}
				cardNum--;
				
			}
		};
	}
	
	//the callback receive when the user "sets" the date in the dialog
		/**
		 * @uml.property  name="mDateSetListener"
		 * @uml.associationEnd  multiplicity="(1 1)"
		 */
		private DatePickerDialog.OnDateSetListener
		mDateSetListener = new DatePickerDialog.OnDateSetListener() {
			 
			public void onDateSet(DatePicker view, int year, int monthOfYear,
					int dayOfMonth) {
				
				//get the current date
				final Calendar c = Calendar.getInstance();
				mYear = year;
				mMonth = monthOfYear;
				mDay = dayOfMonth;
				
				
				      
				
				updateDisplay();
				
			}
			
			 
		        
		};
		
		//updates the dates in the textView
		private void updateDisplay(){
			etDateOpen.setText(new StringBuilder()
					//month is 0 base so add 1
					.append(mMonth + 1).append("-")
					.append(mDay).append("-")
					.append(mYear).append(" "));
		}
		
		
		//For Date account open
		
		
		
		//the callback receive when the user "sets" the date in the dialog
		/**
		 * @uml.property  name="mDateSetListener2"
		 * @uml.associationEnd  multiplicity="(1 1)"
		 */
		private DatePickerDialog.OnDateSetListener
		 mDateSetListener2 = new DatePickerDialog.OnDateSetListener() {
			 
			public void onDateSet(DatePicker view, int year, int monthOfYear,
					int dayOfMonth) {
				
				//get the current date
				final Calendar c = Calendar.getInstance();
				mYear = year;
				mMonth = monthOfYear;
				mDay = dayOfMonth;
				updateDisplay2();
				
			}
		};
		
		//updates the dates in the textView
		private void updateDisplay2(){
			etDateOpen2.setText(new StringBuilder()
					//month is 0 base so add 1
					.append(mMonth + 1).append("-")
					.append(mDay).append("-")
					.append(mYear).append(" "));
		}
		
		//the callback receive when the user "sets" the date in the dialog
				/**
				 * @uml.property  name="mDateSetListener3"
				 * @uml.associationEnd  multiplicity="(1 1)"
				 */
				private DatePickerDialog.OnDateSetListener
				mDateSetListener3 = new DatePickerDialog.OnDateSetListener() {
					 
					public void onDateSet(DatePicker view, int year, int monthOfYear,
							int dayOfMonth) {
						
						//get the current date
						final Calendar c = Calendar.getInstance();
						mYear = year;
						mMonth = monthOfYear;
						mDay = dayOfMonth;
						
						
						      
						
						updateDisplay3();
						
					}
					
					 
				        
				};
				
				//updates the dates in the textView
				private void updateDisplay3(){
					etDateOpen3.setText(new StringBuilder()
							//month is 0 base so add 1
							.append(mMonth + 1).append("-")
							.append(mDay).append("-")
							.append(mYear).append(" "));
				}
	
	private OnClickListener nextPage() {
		final Context context = this;
		return new OnClickListener() {
			public void onClick(View v) {
				
				
				 Intent intent = new Intent(context, Credit_score_form_sec_c.class);
                 startActivity(intent); 
                 
			}
		};
	}
	
	private OnClickListener backPage() {
		final Context context = this;
		return new OnClickListener() {
			public void onClick(View v) {
				
				
				 Intent intent = new Intent(context, Credit_score_form_sec_a.class);
                 startActivity(intent); 
                 
			}
		};
	}
	

}
